﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace SAIN.MVC.Controllers
{
    public class DataTransactionsController : Controller
    {

        public ActionResult List()
        {
            try
            {
                BC.DataFramework.DataTransactionsBC bc = new BC.DataFramework.DataTransactionsBC();
                List<BE.DataFramework.DataTransactionsBE> list = bc.Select(new BE.DataFramework.DataTransactionsBE());
                return View(list);
            }
            catch (Exception ex)
            {
                throw new Exception("DataTransactionsController - List - ", ex);
            }
        }

        //
        // GET: /DataTransactions/

        public ActionResult Index()
        {
            return View();
        }

        //
        // GET: /DataTransactions/Details/5

        public ActionResult Details(int id)
        {
            return View();
        }

        //
        // GET: /DataTransactions/Create

        public ActionResult Create()
        {
            return View();
        } 

        //
        // POST: /DataTransactions/Create

        [HttpPost]
        public ActionResult Create(string sName, int iConnectionId, string sProcedureName)
        {
            try
            {
                BE.DataFramework.DataTransactionsBE item = new BC.DataFramework.DataTransactionsBC().Create(
                    new BE.DataFramework.DataTransactionsBE()
                {
                    sName = sName,
                    iConnectionId = iConnectionId,
                    sProcedureName = sProcedureName
                });
                
                return Json(new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(item), JsonRequestBehavior.AllowGet);
            }
            catch
            {
                return View();
            }
        }
        
        //
        // GET: /DataTransactions/Edit/5
 
        public ActionResult Edit(int id)
        {
            BE.DataFramework.DataTransactionsBE item =
                new BC.DataFramework.DataTransactionsBC().Select(new BE.DataFramework.DataTransactionsBE() { iDataTransactionId = id }).First();
            return View();
        }

        //
        // POST: /DataTransactions/Edit/5

        [HttpPost]
        public ActionResult Edit(int id, FormCollection collection)
        {
            try
            {
                // TODO: Add update logic here
 
                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }

        //
        // GET: /DataTransactions/Delete/5
 
        public ActionResult Delete(int id)
        {
            return View();
        }

        //
        // POST: /DataTransactions/Delete/5

        [HttpPost]
        public ActionResult Delete(int id, FormCollection collection)
        {
            try
            {
                // TODO: Add delete logic here
 
                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }
    }
}
